<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>{{session("szyLy.title")}} </title>
  <meta name="keywords" content={{session("szyLy.keywords")}} />
  <meta name="description" content={{session("szyLy.description")}} />
  <link rel="shortcut icon" href="/style/home/img/1.png">
  <link rel="stylesheet" href="/style/home/css/shop.css">
  <script src="/style/home/js/jquery.js"></script>
  <style type="text/css">

         .bc_probtn input {
            float: right;
            width: 160px;
            height: 38px;
            line-height: 38px;
            background: #e2231a;
            border: 1px solid #d9d8d6;
            border-radius: 5px;
            text-align: center;
            color: #fff;
            font-size: 20px;
}
  </style>
  <!-- // <script src="/style/home/js/shop.js"></script> -->
</head>
<body>
@include("home.public.header1")

<!-- logo -->
<div class="top_logob">
    <img src="/style/home/img/pic-13.jpg" class="top_logob_imga">
    <img src="/style/home/img/pic-12.jpg" class="top_logob_imgb">
</div>

<div class="buycart w1200">
    @if($shop)
<div id="cart_main">
    <div class="bc_option clearfix">
    <div class="bc_all clearfix active">
 </div>
</div>

<form action="/jiesuan" method="post">
<div class="bc_table" id="main_table">
    <table cellpadding="0" cellspacing="0">
        <tbody>
          <tr>
            <th colspan="3" width="462">商品</th>
            <th width="163">描述</th>
            <th width="152">单价</th>
            <th width="152">数量</th>
            <th width="152">金额</th>
            <th width="117">操作</th>
          </tr>
        </tbody>
    </table>
    <table cellpadding="0" cellspacing="0">
        
        <!--带服务-->
         <tbody>
            <?php $tot=0; ?>

            
            @foreach($shop as $car)
            <tr class=" active" gcode="52770" stock="18">
                <td width="57" class="bc_table_sel">
                    <input type="checkbox" checked name="goods[]" value="{{$car['id']}}" />
                </td>
                <td width="148" class="bc_table_img">
                    <a href="/goods/{{$car['id']}}" target="_blank">
                         <img src="{{$car['goodsInfo']['img']}}" alt="">
                    </a>
                    <div class="bc_zhezhao"></div>
                </td>
                <td width="257" class="bc_proname bc_name_gift">
                    <a href="{{$car['id']}}" target="_blank">{{$car['goodsInfo']['goodsname']}}</a>
                    
                </td>
                <td width="163"><a href="/goods/{{$car['id']}}" target="_blank">{{$car['goodsInfo']['title']}}</a> </td>
                <td width="152" style="position:relative;">
                    <span class="current_price">{{$car['goodsInfo']['price']}}</span>
                    <!--满减-->
                 </td>
                <td width="152" text-align:center>
                    <label class="i_box clearfix">
                     <input type="hidden"  name="kucun" id="kucun" value="{{$car['goodsInfo']['num']}}" />
                        <input class="pro_less J_minus"  money="{{$car['goodsInfo']['price']}}" ids="{{$car['goodsInfo']['id']}}" type="button" value="-" >
                        <input class="pro_num J_input" type="text" id="goodsNumber" value="{{$car['num']}}" style="ime-mode: disabled;" >
                        <input class="pro_add J_add" id="add" money="{{$car['goodsInfo']['price']}}" ids="{{$car['goodsInfo']['id']}}" type="button" value="+" >
                    </label>

                </td>

                <?php 

                    $money=$car['goodsInfo']['price']*$car['num'];

                    $tot+= $money;
                 ?>
                <td width="152" id="money{{$car['goodsInfo']['id']}}" class="bc_red">{{$money}}</td>
                <td width="117" style="text-align:left">
                    <a href="javascript:;" style="color: #000" title="删除" onclick="deleline(this,{{$car['goodsInfo']['id']}})">删除</a>
                    <br>                    
                </td>
            </tr>

            @endforeach
            

           
    </tbody>
</table>
</div>
<div class="bc_num clearfix">
   
    <ul class="bc_num_fr">
        <li>合计：<span class="bc_red" id="totalmoneyf"><span id="heji">{{$tot}}</span> 元</span></li>
    </ul>
</div>
    <div class="bc_probtn">
        {{csrf_field()}}
        <input type="submit" id="submit" value="去结算"  event-name="PC端_去购物">
        <!-- <a href="./zhifu.html" title="去结算"  event-name="PC端_去结算">去结算</a> -->
    </div>

</div>

</form>

@else

   <div class="bc_table" id="main_table">
    <table cellpadding="0" cellspacing="0">
            <tbody>
              <tr>        
                <th >空空如也</th>
              </tr>
            </tbody>
    </table>
    <table cellpadding="0" cellspacing="0">
        
        <!--带服务-->
         <tbody><tr class=" active" gcode="52770" stock="18">
                
              
                <td width="257" height="50px" class="text-align:center">
                    
                     <a href="/">购物车空空如也，请购物</a>
                </td>
                
                 <div class="bc_probtn clearfix">
                     <a href="/" title="去购物"  event-name="PC端_去购物">去购物</a>
                 </div>
                   
            </tr>
    </tbody>
</table>
</div>
@endif


</div>
 <div class="footer">
   <img src="/style/home/img/99999.png" alt="">

   <img src="/style/home/img/9999.png" alt="">
 </div>
</body>


<script>

    // 删除方法

    function deleline(obj,id){

        $.post("/CarDel",{id:id,"_token":"{{csrf_token()}}"},function(data){
            // 判断是否成功

            if (data) {
                // 移除对应商品
                $(obj).parent().parent().remove();
                window.location=location;
            };
        });

    }


    // 数量+
    $(".J_add").click(function(){
        
        // 获取商品的ID

        id=$(this).attr('ids');

        obj=$(this);

         // 获取库存
        var kucun=$('#kucun').val();
        //转为number
        kucun=parseInt(kucun); 
        //选择的数量
        var num=$("#goodsNumber").val(); //
        num=parseInt(num)+1;  //    2

        if(num>=kucun){
            $("#goodsNumber").val(kucun-1);
           $("#add").attr("disabled", true);   
        }
        // 发送ajax请求

        $.post("/CarAdd",{id:id,"_token":"{{csrf_token()}}"},function(data){

            if (data) {
                // js修改输入框的数量
                num=obj.prev().val();

                num=Number(num);

                obj.prev().val(++num);

            

                // 获取商品的价格

                price=Number(obj.attr("money"));

                // 让小计发生改变

                money=Number($("#money"+id).html());
                money=money+price;

                $("#money"+id).html(money);

                // 合计

                tot=Number($("#heji").html());

                tot=tot+price;

                $("#heji").html(tot);


            };
        });
    });

    // 数量-
    $(".J_minus").click(function(){
        
         $("#add").attr("disabled", false);   
        // 获取商品的ID

        id=$(this).attr('ids');

        obj=$(this);

        num=obj.next().val();

        if (num<=1) {
            return "";
        };


        // 发送ajax请求

        $.post("/CarJian",{id:id,"_token":"{{csrf_token()}}"},function(data){

            if (data) {
                // js修改输入框的数量
                num=obj.next().val();

                num=Number(num);

                obj.next().val(--num);

                // 获取商品的价格

                price=Number(obj.attr("money"));

                // 让小计发生改变

                money=Number($("#money"+id).html());
                money=money-price;

                $("#money"+id).html(money);

                // 合计

                tot=Number($("#heji").html());

                tot=tot-price;

                $("#heji").html(tot);
            };
        });

    });
            
</script>

</html>